package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.common.utils.ValidateCodeUtils;
import com.itheima.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/validatecode")
public class ValidateCodeController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/send4Login")
    public Result send4Login(@RequestParam("telephone") String telephone) {
        String validateCode = String.valueOf(ValidateCodeUtils.generateValidateCode(4));
        log.info("验证码:{}", validateCode);
        redisTemplate.opsForValue().set("MesValidateCode", validateCode);
        return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
    }
}
